//
//  RefreshToken.m
//  EcmDoctor
//
//  Created by Mac on 16/3/7.
//  Copyright © 2016年 张进. All rights reserved.
//

#import "RefreshToken.h"

@implementation RefreshToken
//methodname
//String
//是
//MyRS / changeToken
//接口方法名
//userid
//String
//是
//
//用户ID
//token
//String
//是
//
//旧的token

+(void)changeTokenfailure:(void (^)(NSError *))failure
{
      NSString *userid= [SSKeychain passwordForService:APP_SERVICE_NAME account:APP_DOCTORINFOID_KEY];
    NetWorkBaseRequest *req = [[NetWorkBaseRequest alloc] init];
     NSString *tokenValue = [SSKeychain passwordForService:[AppUtils appServiceName] account:[AppUtils tokenKey]];
    NSLog(@"----------%@--",tokenValue);
    req.moduleName = @"MyRS";
    req.methodName = @"changeToken";
    [req setValue:userid forKey:@"userid"];
    [req setValue:tokenValue forKey:@"token"];
    
    [NetWorkUtil requestWithPOST:req success:^(NetWorkBaseResponse *responseObject) {
        NSError *error = nil;
        
        NSLog(@"--------------%@",responseObject);
      
        if (responseObject.code.integerValue == 1) {
       [SSKeychain deletePasswordForService:[AppUtils appServiceName]account:[AppUtils tokenKey]];
       [SSKeychain setPassword:responseObject.data forService:[AppUtils appServiceName] account:[AppUtils tokenKey]];
                return;

        }
        else{
            error = [NSError errorWithDomain:responseObject.msg code:responseObject.code.integerValue userInfo:nil];
            failure(error);
        }
        
    } failure:^(NSError *error) {
        failure(error);
        
    } cache:NO];

}
@end
